1. Field of the Invention
The invention relates to a method for managing memory, more particularly to a defragmentation method for a machine-readable storage device.
2. Description of the Related Art
After a hard disk of a computer has been used for a period of time, the number of accesses to files stored in the hard disk has increased such that it is less likely to store files in a contiguous memory space in the hard disk. In other words, it is less likely to store files in contiguous memory cells in the hard disk. As a result, a single file is divided into pieces that are respectively stored in a plurality of segments of memory cells (also known as “file segments”) scattered in the hard disk. Consequently, when the file is to be accessed, it is required for a read-write head of the hard disk to look into different locations in the hard disk. This degrades data access efficiency of the hard disk, and also wears out the read-writing head.
In order to solve the aforementioned problem, there are currently a plurality of defragmentation software that employ different algorithms to conduct defragmentation on hard disks, in which file fragments are rearranged such that pieces of the same file are stored in contiguous memory cells to the best possible, and such that empty memory cells (also known as “free space fragments”) are gathered together in a contiguous manner.
With the advancement of semiconductor manufacturing technology, flash memories are made into solid-state drives (SSDs) that have large storage capacities to replace conventional hard disks (HDs). The same problem of having file fragments and free space fragments also exists in solid-state drives. However, in view of the fact that a flash memory can only be accessed a certain number of times during its service life, the service life of a SSD may be significantly and adversely reduced if the defragmentation algorithms for hard disks are used for defragmentation. Due to this constraint, current defragmentation software is directed for defragmentation on only hard disks or only solid-state drives, and cannot be used for defragmentation on both hard disks and solid-state drives without adverse effects.